<?php

/**
 * 【后台】员工通讯录
 *
 * @author		maxuebing<276654894@qq.com>
 * @copyright	Copyright (c) , Chinasofti, Inc.
 */
class contactsAction extends backendAction{
	
	/**
	 * 列表
	 */
	public function index(){
		$cityName	= I('cityName');
		$storeName	= I('storeName');
		$realName	= I('realName');
		$jobPost	= I('jobPost');
		$phone		= I('phone');
		$email		= I('email');
		
		$cityName	&& $map['c.name']	= array('like',"%{$cityName}%");
		$storeName	&& $map['s.name']	= array('like',"%{$storeName}%");
		$realName	&& $map['u.name']	= array('like',"%{$realName}%");
		$jobPost	&& $map['u.jobPost']= $jobPost;
		$phone		&& $map['u.phone']	= array('like',"{$phone}%");
		$email		&& $map['u.email']	= array('like',"{$email}%");

		$map['u.id'] = array('gt', 1);
		$map['u.status'] = 1;
		
		$count = D('admin')->alias('u')
				->join(C('DB_PREFIX')."store AS s ON s.id = u.storeId")
				->join(C('DB_PREFIX')."region AS r ON r.id = u.regionId")
				->join(C('DB_PREFIX')."region AS c ON c.id = r.pid")
				->where($map)->count();
		
        $pager = new Page($count, 20);
		
		$page = $pager->show();
		
		$field	= array(
			'u.realName',
			'u.phone',
			'u.email',
			'u.jobPost',
			'c.name'=> 'cityName',
			's.name'=> 'storeName',
		);
		
		$list = D('admin')->alias('u')->field($field)
				->join(C('DB_PREFIX')."store AS s ON s.id = u.storeId")
				->join(C('DB_PREFIX')."region AS r ON r.id = u.regionId")
				->join(C('DB_PREFIX')."region AS c ON c.id = r.pid")
				->where($map)
				->limit($pager->firstRow.','.$pager->listRows)->select();
		
		$this->assign("page", $page);
		$this->assign('list', $list);
		$this->display();
	}
	
}

/* End of file contactsAction.class.php */
